package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUserReport;
import com.ruoyi.system.service.ISysUserReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 举报Controller
 * 
 * @author ruoyi
 * @date 2025-08-24
 */
@RestController
@RequestMapping("/system/report")
@Api(tags = "举报")
public class SysUserReportController extends BaseController
{
    @Autowired
    private ISysUserReportService sysUserReportService;

    /**
     * 查询举报列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    @ApiOperation("举报列表")
    public TableDataInfo list(SysUserReport sysUserReport)
    {
        startPage();
        List<SysUserReport> list = sysUserReportService.selectSysUserReportList(sysUserReport);
        return getDataTable(list);
    }

    /**
     * 导出举报列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "举报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserReport sysUserReport)
    {
        List<SysUserReport> list = sysUserReportService.selectSysUserReportList(sysUserReport);
        ExcelUtil<SysUserReport> util = new ExcelUtil<SysUserReport>(SysUserReport.class);
        util.exportExcel(response, list, "举报数据");
    }

    /**
     * 获取举报详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysUserReportService.selectSysUserReportById(id));
    }

    /**
     * 新增举报
     */
    @Log(title = "举报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @Anonymous
    public AjaxResult add(@RequestBody SysUserReport sysUserReport)
    {
        return toAjax(sysUserReportService.insertSysUserReport(sysUserReport));
    }

    /**
     * 修改举报
     */
    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "举报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserReport sysUserReport)
    {
        return toAjax(sysUserReportService.updateSysUserReport(sysUserReport));
    }

    /**
     * 审核举报
     */
    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "审核举报", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody SysUserReport sysUserReport)
    {
        // 设置审核状态为已处理
        sysUserReport.setStatus(1);
        return toAjax(sysUserReportService.updateSysUserReport(sysUserReport));
    }

    /**
     * 删除举报
     */
    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "举报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysUserReportService.deleteSysUserReportByIds(ids));
    }
}
